<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
</head>
<body>
    <jsp:include page="head.jsp"></jsp:include>


    <div id="picture">
        <div  data-options=" region:'east',split:true,style:{margin:'75px auto'}"
              class="easyui-panel " title="用户登录" style="width:300px;text-align: center;">
            <div style="padding:10px 60px 20px 60px">
                <form id="ff" class="easyui-form" method="post" data-options="novalidate:true">
                    <table cellpadding="5">
                        <tr>
                            <td><input value="admin" name="username" class="easyui-textbox" required="true" data-options="prompt:'账号'" iconCls="icon-man" iconAlign=left style="width:100%;height:32px"/></td>
                        </tr>
                        <tr>
                            <td><input value="123456" name="password" type="password" class="easyui-textbox" required="true" iconCls="icon-lock" iconAlign=left style="width:100%;height:32px"></input></td>
                        </tr>

                    </table>
                </form>
                <div style="text-align:center;padding:5px 0px;width: 195px;">
                    <a href="javascript:void(0)" onclick="submitForm()" class="easyui-linkbutton" style="width:45%;height:32px">登录</a>&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="/register" class="easyui-linkbutton" style="width:45%;height:32px">注册</a>
                </div>
            </div>
        </div>

    </div>

    <script>

        function submitForm(){
            $('#ff').form('submit',{
                url: '/login',
                onSubmit:function() {
                    return $(this).form('enableValidation').form('validate');
                },
                success: function(data){
                    let res = $.parseJSON(data);
                    console.log(res);

                    if(res.success) {
                        window.location = '/';
                    } else {
                        $.messager.show({
                            title: 'Error',
                            msg: res.msg
                        });
                    }
                }
            });
        }

    </script>
</body>
</html>